.set LOCALID_KYOGRE, 1

MarineCave_End_MapScripts:: @ 823AFDF
	map_script MAP_SCRIPT_ON_RESUME, MarineCave_End_OnResume
	map_script MAP_SCRIPT_ON_TRANSITION, MarineCave_End_OnTransition
	.byte 0

MarineCave_End_OnResume: @ 823AFEA
	call_if_set FLAG_SYS_CTRL_OBJ_DELETE, MarineCave_End_EventScript_TryRemoveKyogre
	end

MarineCave_End_EventScript_TryRemoveKyogre:: @ 823AFF4
	specialvar VAR_RESULT, GetBattleOutcome
	compare VAR_RESULT, B_OUTCOME_CAUGHT
	goto_if_ne Common_EventScript_NopReturn
	removeobject LOCALID_KYOGRE
	return

MarineCave_End_OnTransition: @ 823B008
	call_if_unset FLAG_DEFEATED_KYOGRE, MarineCave_End_EventScript_ShowKyogre
	end

MarineCave_End_EventScript_ShowKyogre:: @ 823B012
	clearflag FLAG_HIDE_MARINE_CAVE_KYOGRE
	setvar VAR_TEMP_1, 1
	return

MarineCave_End_EventScript_Kyogre:: @ 823B01B
	lockall
	applymovement OBJ_EVENT_ID_PLAYER, Common_Movement_FaceUp
	waitmovement 0
	applymovement LOCALID_KYOGRE, MarineCave_End_Movement_KyogreApproach
	waitmovement 0
	waitse
	playmoncry SPECIES_KYOGRE, 2
	delay 40
	waitmoncry
	setvar VAR_LAST_TALKED, LOCALID_KYOGRE
	msgbox MarineCave_End_Text_KyogreSpeechBeforeBattle1, MSGBOX_DEFAULT
	playmoncry SPECIES_KYOGRE, 2
	msgbox MarineCave_End_Text_KyogreSpeechBeforeBattle2, MSGBOX_DEFAULT
	@setwildbattle SPECIES_KYOGRE, 70, ITEM_NONE
	setlegendarybattle SPECIES_KYOGRE, 70, ITEM_BLUE_ORB, LEGENDARY_MON_KYOGRE
	setflag FLAG_SYS_CTRL_OBJ_DELETE
	special BattleSetup_StartLegendaryBattle
	waitstate
	clearflag FLAG_SYS_CTRL_OBJ_DELETE
	setvar VAR_TEMP_1, 0
	specialvar VAR_RESULT, GetBattleOutcome
	@compare VAR_RESULT, B_OUTCOME_WON
	@goto_if_eq MarineCave_End_EventScript_DefeatedKyogre
	compare VAR_RESULT, B_OUTCOME_RAN
	goto_if_eq MarineCave_End_EventScript_RanFromKyogre
	compare VAR_RESULT, B_OUTCOME_PLAYER_TELEPORTED
	goto_if_eq MarineCave_End_EventScript_RanFromKyogre
	setvar VAR_SHOULD_END_ABNORMAL_WEATHER, 1
	setflag FLAG_DEFEATED_KYOGRE
	msgbox MarineCave_End_Text_KyogreSpeechAfterBattle, MSGBOX_DEFAULT
	giveitem ITEM_KYOGRE_VOUCHER, 1
	closemessage
	setvar VAR_0x8004, SPECIES_KYOGRE
	goto Common_EventScript_DefeatLegendary
	@releaseall
	@end

@MarineCave_End_EventScript_DefeatedKyogre:: @ 823B084
@	setvar VAR_SHOULD_END_ABNORMAL_WEATHER, 1
@	setflag FLAG_DEFEATED_KYOGRE
@	goto Common_EventScript_RemoveStaticPokemon
@	end

MarineCave_End_EventScript_RanFromKyogre:: @ 823B092
	setvar VAR_0x8004, SPECIES_KYOGRE
	goto Common_EventScript_LegendaryFlewAway
	end

MarineCave_End_Movement_KyogreApproach: @ 823B09D
	init_affine_anim
	walk_down_start_affine
	delay_16
	delay_16
	walk_down_affine
	delay_16
	delay_16
	walk_down_affine
	delay_16
	delay_16
	clear_affine_anim
	step_end

MarineCave_End_Text_KyogreSpeechBeforeBattle1:
	.string "人类……\n"
	.string "终究又回到这里了吗。\p"
	.string "从古至今……因世界的自然……\n"
	.string "我和它的恩怨从未了结。\p"
	.string "所制造出的无限的海洋被尘土填满……\n"
	.string "广阔陆地被海水埋没……\p"
	.string "这样，直到尽头……\n"
	.string "战斗也未分出胜负。\p"
	.string "结局，\n"
	.string "双方无不例外地陷入封印的诅咒。\p"
	.string "作为海洋化身的我，\n"
	.string "尘封在你们的记忆中………………$"
	
MarineCave_End_Text_KyogreSpeechBeforeBattle2:	
	.string "{COLOR RED}-----嘎噢噢噢！{COLOR DARK_GREY}{PAUSE 0x40}\p"
	.string "现在已经不需要了。\p"
	.string "因为拥有了周围的事物，\n"
	.string "所以静驻在此处。\p"
	.string "假设你……\n"
	.string "拥有降伏海洋的沉着……\p"
	.string "{COLOR RED}那{PAUSE 0x10}就{PAUSE 0x10}上{PAUSE 0x10}前{PAUSE 0x10}一{PAUSE 0x10}步{PAUSE 0x10}吧！$"

MarineCave_End_Text_KyogreSpeechAfterBattle:
	.string "你确实拥有着对应海洋的沉着……\n"
	.string "说不定，我和那家伙难得没有意见相左。\p"
	.string "开启世界海洋化的计程吧……\n"
	.string "我会协助你的。\p"
	.string "毕竟，这是我为数不多……\n"
	.string "且执着的事情。$"

